
// -----------------------------------------------------------------------------

#pragma once

#include <windows.h>
#include <bcrypt.h>

// -----------------------------------------------------------------------------

namespace Kif
{
namespace Win32
{
namespace Security
{
namespace Cryptography
{

enum CryptAlgorithm
{
   CryptAlgorithm_Unknown = 0,

   // data encryption

   CryptAlgorithm_TripleDES = 100,
   CryptAlgorithm_TripleDES_112 = 105,
   CryptAlgorithm_AES = 110,           // advanced encryption standard (sym)
   // CryptAlgorithm_AES_GMAC = 115,   // AES Galois message auth. (sym)
   CryptAlgorithm_DES = 120,           // Data encryption standard (sym)
   CryptAlgorithm_DESX = 125,          // Extended data encryption std (sym)
   CryptAlgorithm_RC2 = 130,           // RC2 block symmetric encryption
   CryptAlgorithm_RC4 = 135,           // RC4 symmetric encryption 

   // keys - secret messages handling and management

   CryptAlgorithm_DH = 400,            // Diffie-Hellman key exchange
   CryptAlgorithm_ECDH_P256 = 405,     // 256-bit prime elliptic curve DH
   CryptAlgorithm_ECDH_P384 = 410,     // 384-bit prime elliptic curve DH
   CryptAlgorithm_ECDH_P521 = 415,     // 521-bit prime elliptic curve DH
   CryptAlgorithm_RSA = 420,           // RSA public key

   // digital signature

   CryptAlgorithm_DSA = 600,           // digital signature algorithm
   CryptAlgorithm_ECDSA_P256 = 605,    // 256-bit prime elliptic curve dig. sig.
   CryptAlgorithm_ECDSA_P384 = 610,    // 384-bit prime elliptic curve dig. sig.
   CryptAlgorithm_ECDSA_P521 = 615,    // 384-bit prime elliptic curve dig. sig.
   CryptAlgorithm_RSA_SIGN = 620,      // RSA signature (NOT SUPPORTED)

   // hash

   CryptAlgorithm_MD2 = 800,           // MD2 hash
   CryptAlgorithm_MD4 = 805,           // MD4 hash
   CryptAlgorithm_MD5 = 810,           // MD5 hash

   CryptAlgorithm_SHA1 = 1000,         // 160-bit secure hash
   CryptAlgorithm_SHA256 = 1005,       // 256-bit secure hash
   CryptAlgorithm_SHA384 = 1010,       // 384-bit secure hash
   CryptAlgorithm_SHA512 = 1015,       // 512-bit secure hash

   // random number generation

   CryptAlgorithm_RNG = 1200,             // random-number generator
   // CryptAlgorithm_RNG_DUAL_EC = 1205,  // dual elliptical curve RNG
   CryptAlgorithm_RNG_FIPS186_DSA = 1210  // dual elliptical curve RNG
}  ;

// -----------------------------------------------------------------------------

class Provider
{
private:

BCRYPT_ALG_HANDLE hAlgorithmHandle;

public:

   NTSTATUS LastReturnedStatus;
   wchar_t *GetAlgorithmId(CryptAlgorithm algorithm);

   BCRYPT_ALG_HANDLE GetHandle()
   {
      return hAlgorithmHandle;
   }

   bool OpenAlgorithmProvider(CryptAlgorithm algorithm);
   inline bool IsOpened()
   {
      return hAlgorithmHandle == NULL;
   }

   void Dispose();

   Provider();
   Provider(CryptAlgorithm algorithm);
  ~Provider();

}  ;  // end of Provider class

}  // end of Kif::Win32::Security::Cryptography
}  // end of Kif::Win32::Security
}  // end of Kif::Win32
}  // end of Kif

